#pragma once

#include <iostream>
#include <string>
#include <functional>
#include "inetAddr.hpp"
#include "Reactor.hpp"
// 封装fd, 给每一个fd分配一套缓冲区

class Reactor;
class Channel;
class Connection;

using handler_t = std::function<std::string(std::string &inbuffer)>;

class Connection
{
public:
    Connection() : _owner(nullptr), _events(0), _handler(nullptr) {}

    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Execpter() = 0;
    virtual int GetFd() = 0;

    void Register(handler_t handler)
    {
        _handler = handler;
    }

    void SetEvent(const uint32_t &events)
    {
        _events = events;
    }

    void SetOwner(Reactor *owner)
    {
        _owner = owner;
    }

    Reactor *GetOwner() { return _owner; }
    uint32_t GetEvents() { return _events; }

    ~Connection() {}

private:
    // 回指指针
    Reactor *_owner;

    // 关心事件
    uint32_t _events;

public:
    handler_t _handler;
};